package atom;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : AtomDemo1
 * @Author : 54061
 * @Date: 2022/2/16 20:50
 */
public class AtomDemo1 {
    public static void main(String[] args) {
        Target1 target =new Target1();
        for (int i = 0; i<100;i++){
            new Thread(target).start();
        }

    }
}
class Target1 implements Runnable{
    private int count =0;
    private Object obj = new Object();

    @Override
    public void run() {
    for (int i = 0; i <1000;i++){
        //解决方案1 :对原子性的操作进行上锁
        synchronized (obj){
            count++;//非原子性的操作
            System.out.println("已经送了"+count+"个冰淇淋");
        }
    }
    }

}